<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2023/5/11
  Time: 10:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<%String path = request.getContextPath()+"/";%>
<html>
<head>
    <base href="<%=path%>">
    <title>部门列表</title>
    <script type="text/javascript" src="webjars/jquery/3.2.0/jquery.js"></script>
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap-theme.min.css" integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
    <script src="hplus/js/plugins/layer/layer.min.js" type="text/javascript"></script>
    <style>
    .row{
        background-color: #FFFFFF;
        margin: 10px 10px;
        border-radius: 10px;
        box-shadow:1px 1px 3px #8c8c8c;
        padding-top: 7px;
    }
</style>
</head>
<body>
<div class="container" style="background-color: #f3f3f4;width:100%">
<div class="row" style="">
    <div class="col-xs-12 col-lg-12" >
        <form method="post" action="dept/list" class="form-inline">
            <div class="form-group">
                <label >部门名称:</label>
                <input type="text" class="form-control" name="deptName" value="${dept.deptName}">
            </div>
            <div class="form-group">
                <label >部门状态:</label>
                <select name="status" class="form-control">
                    <option value="-1">全部</option>
                    <option value="0" <c:if test="${dept.status==0}">selected</c:if> >启用</option>
                    <option value="1" <c:if test="${dept.status==1}">selected</c:if>>停用</option>
                </select>
            </div>

            <button type="submit" class="btn btn-warning"><span class="glyphicon glyphicon-search"></span>&nbsp;搜索</button>
            <button type="reset" class="btn btn-warning"><span class="glyphicon glyphicon-repeat"></span>&nbsp;重置</button>

        </form>
    </div>
</div>

<div class="row">
    <div class="col-xs-12 col-lg-12">
        <div>
            <button class="btn btn-warning" onclick="$.modal.openWin('新增用户信息','dept/toEdit','500px','500px');"><span class="glyphicon glyphicon-plus"></span>新增</button>
            <button class="btn btn-warning" onclick="removes();"><span class="glyphicon glyphicon-trash"></span>删除</button>

        </div>
    <table class="table table-striped table-hover table-bordered">
        <thead>
        <tr>
            <th><input type="checkbox" onclick="choose(this);"></th>
            <th>部门名称</th>
            <th>排序</th>
            <th>状态</th>
            <th>创建时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <c:choose>
            <c:when test="${fn:length(page.list)>0}">
                <c:forEach items="${page.list}" var="dept" >
                    <tr>
                        <td><input type="checkbox" name="ids" value="${dept.id}"/> </td>
                        <td>${dept.deptName}</td>
                        <td>${dept.sort}</td>
                        <td>
                        <c:choose>
                            <c:when test="${dept.status==0}">
                                <span class="label label-success">启用</span>
                            </c:when>
                            <c:otherwise>
                                <span class="label label-danger">停用</span>
                            </c:otherwise>
                        </c:choose>
                        </td>
                        <td>${dept.gmtCreate}</td>
                        <td>
                            <a href="dept/toEdit?id=${dept.id}">编辑</a>&nbsp;&nbsp;
                            <a href="#">新增</a>&nbsp;&nbsp;
                            <a href="javascript:void(0)" onclick="remove('${dept.id}')">删除</a>&nbsp;&nbsp;
                        </td>
                    </tr>
                </c:forEach>

            </c:when>
            <c:otherwise>
                <tr>
                    <td colspan="6" style="text-align: center">没有找到匹配的记录</td>
                </tr>
            </c:otherwise>
        </c:choose>
    </table>
</div>
</div>
</div>
</body>
<script type="text/javascript" src="hplus/js/sofwin.js"></script>
<script>

    function remove(id){
        if(confirm("确定删除该数据吗？")){

            $.operator.delete('dept/delete/'+id)
        }

    }
    function choose(obj){
        if(obj.checked){
            // 让下面所有的复选康都选中
          $("input[name=ids]").attr("checked",true);
        }else{
            // 都取消选中
            $("input[name=ids]").removeAttr("checked");
        }
    }
    function removes(){
        // 不能传参，但是需要给后台传数组
        // 可以使用选择器  -- 当客户点击批量删除时，通过选择器选择到当前需要删除的checkbox
        // 可以获取到需要删除的id
        console.info($("input[name=ids]:checked"))
        var checkedInput = $("input[name=ids]:checked");
        var ids=new Array();
        for(var i=0;i<checkedInput.length;i++){
            console.info(checkedInput[i])
            ids.push(checkedInput[i].value)
            // ids+=checkedInput[i].value+",";
        }
        if(checkedInput.length==0){
            alert('请选择需要删除的数据');
            return;
        }
        if(confirm("确定需要删除选中的"+checkedInput.length+"个数据吗？？")) {
            console.info(ids)
            $.ajax({
                url: 'dept/deletes2',
                type: 'POST',
                data:{ids:ids},
                success: function (ret) {
                    if (ret) {
                        alert('删除成功')
                        document.location.href = 'dept/list';
                    } else {
                        alert("删除失败")
                    }
                }
            })
        }
    }
</script>
</html>
